#include<iostream>
#include <cstring>
#include <queue>
#include <string>
using namespace std;

char map[20][20][20];
int visited[20][20][20];
int n;
int startx, starty, startz;
int endx, endy, endz;
int dirx[] = { 1,-1,0,0,0,0 };
int diry[] = { 0,0,1,-1,0,0 };
int dirz[] = { 0,0,0,0,1,-1 };

struct Node
{
	int x, y,z, time;
	Node() : x(0), y(0), z(0), time(0){}
	Node(int x, int y,int z, int time) : x(x), y(y), z(z), time(time){}

	Node(const Node & node) : x(node.x), y(node.y), z(node.z), time(node.time){}
};
int IsEnd(const Node&node)
{
	return node.x == endx&&node.y == endy&&node.z == endz;
}
int IsReachable(int x, int y, int z)
{
	if (x<0 || y<0 || z<0 || x >= n || y >= n || z >= n || visited[x][y][z] ||map[z][x][y]!='O' )
		return 0;
	return 1;
}
int sol()
{
	queue<Node> q;
	Node now(startx, starty, startz, 0);
	q.push(now);
	visited[startx][starty][startz] = 1;
	while(!q.empty())
	{
		now = q.front();
		q.pop();
		if (IsEnd(now))
			return now.time;
		for(int i=0;i<6;i++)
		{
			Node next = now;
			next.x += dirx[i];
			next.y += diry[i];
			next.z += dirz[i];
			if(IsReachable(next.x,next.y,next.z))
			{
				next.time++;
				q.push(next);
				visited[next.x][next.y][next.z] = 1;
			}
		}
	}
	return -1;
}


int main()
{
	string str;
	while(cin>>str>>n)
	{
		for(int i=0;i<n;i++)
		{
			for (int j = 0; j < n; j++)
				cin >> map[i][j];
		}
		cin >> startx >> starty >> startz;
		cin >> endx >> endy >> endz;
		cin >> str;		
		memset(visited, 0, sizeof(visited));		
		int ans = sol();
		if (ans != -1)
			cout << n << " " << ans << endl;
		else
			cout << "NO ROUTE" << endl;
	}
	return 0;
}
